<?php
/*
 * 主要功能:
 *
 * dreamxyp(QQ:31996798) - PHP - class.credit.php
 * coding:夏一平
 * 創建時間:2006-11-13
 */
define("credit_imagesDir",surl::get("static")."imgs/credit/");
class credit
{
	/**
	 * 得到等级
	 * $nums 信用值
	 * $type buy|sell
	 */
	static public function getImages($nums,$type='buy')
	{
	    if($type=='buy')
	    {
	        return credit_imagesDir.self::getBuyImages($nums);
	    }elseif($type=='sell')
	    {
	        return credit_imagesDir.self::getSellImages($nums);
	    }
	}
	/**
	 * 得到作为 卖家 的总信用值
	 */
	static public function getTotalSaleCredit($db_member,$urs)
	{
	    $tmp = $db_member->row("select SUM(credit_sell) as cc from member_credit where urs_sell = ? and chk_sell = 1 ",$urs);
	    return (int)$tmp['cc'];
	}
	/**
	 * 得到作为 买家 的总信用值
	 */
	static public function getTotalBuyCredit($db_member,$urs)
	{
	    $tmp = $db_member->row("select SUM(credit_buy) as cc from member_credit where urs_buy = ?  and chk_buy = 1 ",$urs);
	    return (int)$tmp['cc'];
	}
	/**
	 * 得到作为 卖家
	 * 得到时间段的 信用值
	 */
	static public function getSegmentSaleCredit($db_member,$urs)
	{
	    $rs  	 = array(
	    	"wYmd"=>array("good"=>0,"ok"=>0,"bad"=>0),
	    	"mYmd"=>array("good"=>0,"ok"=>0,"bad"=>0),
	    	"m6Ymd"=>array("good"=>0,"ok"=>0,"bad"=>0),
	    	"aYmd"=>array("good"=>0,"ok"=>0,"bad"=>0)
	    );
	    $time    = time();
	    $wYmd = date("Ymd",$time-604800); //7*24*3600
	    $mYmd = date("Ymd",$time-2592000);//30*24*3600
	    $m6Ymd= date("Ymd",$time-15768000);//6*30*24*3600+2.5*24*3600
	    $tmp = $db_member->dataArray("select oYmd,credit_sell from member_credit where urs_sell = ?  and oYmd > $m6Ymd  and chk_sell = 1 ",$urs);
	    foreach($tmp as &$v)
	    {
	     	if($v["oYmd"] > $wYmd)
	     	{
	     	    if($v["credit_sell"] == 1)
	     	    {
	     	        $rs["wYmd"]["good"]++; 
	     	        $rs["mYmd"]["good"]++;
	     	        $rs["m6Ymd"]["good"]++;
	     	    }elseif($v["credit_sell"] == -1)
	     	    {
	     	        $rs["wYmd"]["bad"]++; 
	     	        $rs["mYmd"]["bad"]++;
	     	        $rs["m6Ymd"]["bad"]++;
	     	    }else
	     	    {
	     	        $rs["wYmd"]["ok"]++; 
	     	        $rs["mYmd"]["ok"]++;
	     	        $rs["m6Ymd"]["ok"]++;
	     	    }
	     	}elseif($v["oYmd"] > $mYmd)
	     	{
	     	    if($v["credit_sell"] == 1)
	     	    {
	     	        $rs["mYmd"]["good"]++;
	     	        $rs["m6Ymd"]["good"]++;
	     	    }elseif($v["credit_sell"] == -1)
	     	    {
	     	        $rs["mYmd"]["bad"]++;
	     	        $rs["m6Ymd"]["bad"]++;
	     	    }else
	     	    {
	     	        $rs["mYmd"]["ok"]++;
	     	        $rs["m6Ymd"]["ok"]++;
	     	    }
	     	}else//if($v["oYmd"] > $m6Ymd)
	     	{
	     	    if($v["credit_sell"] == 1)
	     	    {
	     	        $rs["m6Ymd"]["good"]++;
	     	    }elseif($v["credit_sell"] == -1)
	     	    {
	     	        $rs["m6Ymd"]["bad"]++;
	     	    }else
	     	    {
	     	        $rs["m6Ymd"]["ok"]++;
	     	    }
	     	}
	    }
	    $tmp = $db_member->row("select SUM(credit_sell) as cc from member_credit where urs_sell = ? and credit_sell=1 and chk_sell = 1 ",$urs);
	    $rs["aYmd"]["good"]= $tmp["cc"];
	    $tmp = $db_member->row("select SUM(credit_sell) as cc from member_credit where urs_sell = ? and credit_sell=-1 and chk_sell = 1 ",$urs);
	    $rs["aYmd"]["bad"]= $tmp["cc"];
	    $tmp = $db_member->row("select SUM(credit_sell) as cc from member_credit where urs_sell = ? and credit_sell=0 and chk_sell = 1 ",$urs);
		$rs["aYmd"]["ok"]= $tmp["cc"];
		return $rs;
	}
	/**
	 * 得到作为 买家
	 * 得到时间段的 信用值
	 */
	static public function getSegmentBuyCredit($db_member,$urs)
	{
	    $rs  	 = array(
	    	"wYmd"=>array("good"=>0,"ok"=>0,"bad"=>0),
	    	"mYmd"=>array("good"=>0,"ok"=>0,"bad"=>0),
	    	"m6Ymd"=>array("good"=>0,"ok"=>0,"bad"=>0),
	    	"aYmd"=>array("good"=>0,"ok"=>0,"bad"=>0)
	    );
	    $time    = time();
	    $wYmd = date("Ymd",$time-604800); //7*24*3600
	    $mYmd = date("Ymd",$time-2592000);//30*24*3600
	    $m6Ymd= date("Ymd",$time-15768000);//6*30*24*3600+2.5*24*3600
	    $tmp = $db_member->dataArray("select oYmd,credit_buy from member_credit where urs_buy = ?  and oYmd > $m6Ymd  and chk_buy = 1 ",$urs);
	    foreach($tmp as &$v)
	    {
	     	if($v["oYmd"] > $wYmd)
	     	{
	     	    if($v["credit_sell"] == 1)
	     	    {
	     	        $rs["wYmd"]["good"]++; 
	     	        $rs["mYmd"]["good"]++;
	     	        $rs["m6Ymd"]["good"]++;
	     	    }elseif($v["credit_sell"] == -1)
	     	    {
	     	        $rs["wYmd"]["bad"]++; 
	     	        $rs["mYmd"]["bad"]++;
	     	        $rs["m6Ymd"]["bad"]++;
	     	    }else
	     	    {
	     	        $rs["wYmd"]["ok"]++; 
	     	        $rs["mYmd"]["ok"]++;
	     	        $rs["m6Ymd"]["ok"]++;
	     	    }
	     	}elseif($v["oYmd"] > $mYmd)
	     	{
	     	    if($v["credit_sell"] == 1)
	     	    {
	     	        $rs["mYmd"]["good"]++;
	     	        $rs["m6Ymd"]["good"]++;
	     	    }elseif($v["credit_sell"] == -1)
	     	    {
	     	        $rs["mYmd"]["bad"]++;
	     	        $rs["m6Ymd"]["bad"]++;
	     	    }else
	     	    {
	     	        $rs["mYmd"]["ok"]++;
	     	        $rs["m6Ymd"]["ok"]++;
	     	    }
	     	}else//if($v["oYmd"] > $m6Ymd)
	     	{
	     	    if($v["credit_sell"] == 1)
	     	    {
	     	        $rs["m6Ymd"]["good"]++;
	     	    }elseif($v["credit_sell"] == -1)
	     	    {
	     	        $rs["m6Ymd"]["bad"]++;
	     	    }else
	     	    {
	     	        $rs["m6Ymd"]["ok"]++;
	     	    }
	     	}
	    }
	    $tmp = $db_member->row("select SUM(credit_buy) as cc from member_credit where urs_buy = ? and credit_sell=1 and chk_buy = 1 ",$urs);
	    $rs["aYmd"]["good"]= $tmp["cc"];
	    $tmp = $db_member->row("select SUM(credit_buy) as cc from member_credit where urs_buy = ? and credit_sell=-1 and chk_buy = 1 ",$urs);
	    $rs["aYmd"]["bad"] = $tmp["cc"];
	    $tmp = $db_member->row("select SUM(credit_buy) as cc from member_credit where urs_buy = ? and credit_sell=0 and chk_buy = 1 ",$urs);
		$rs["aYmd"]["ok"]  = $tmp["cc"];
		return $rs;
	}
	static public function getList($db_member,$urs,$uT='sale',$cT='in',$page=1,$rows=20)
	{
	    
	}
	/* 下面的私有方法 */
	protected function getSellImages($nums=0)
	{
	    if($nums<101)
	    {
	     	if($nums < 1)
	     	{
	     	    return "zero.gif";
	     	}elseif($nums < 5)
	     	{
	     	   return "sellGold1.gif";
	     	}elseif($nums < 11)
	     	{
	     	    return "sellGold2.gif";
	     	}elseif($nums < 21)
	     	{
	     	    return "sellGold3.gif";
	     	}elseif($nums < 41)
	     	{
	     	    return "sellGold4.gif";
	     	}else//if($nums < 101)
	     	{
	     	    return "sellGold5.gif";
	     	}
	    }else
	    {
	        if($nums > 30000)
	        {
	            return "sellSuper.gif";
	        }elseif($nums > 10000)
	        {
	            return "sellMedal5.gif";
	        }elseif($nums > 3000)
	        {
	            return "sellMedal4.gif";
	        }elseif($nums > 1000)
	        {
	            return "sellMedal3.gif";
	        }elseif($nums > 300)
	        {
	            return "sellMedal2.gif";
	        }else//if($nums > 100)
	        {
	            return "sellMedal1.gif";
	        }
	    }
	}
	protected function getBuyImages($nums,$type='buy')
	{
	    if($nums<101)
	    {
	     	if($nums < 1)
	     	{
	     	    return "zero.gif";
	     	}elseif($nums < 5)
	     	{
	     	   return "buyGold1.gif";
	     	}elseif($nums < 11)
	     	{
	     	    return "buyGold2.gif";
	     	}elseif($nums < 21)
	     	{
	     	    return "buyGold3.gif";
	     	}elseif($nums < 41)
	     	{
	     	    return "buyGold4.gif";
	     	}else//if($nums < 101)
	     	{
	     	    return "buyGold5.gif";
	     	}
	    }else
	    {
	        if($nums > 5000)
	        {
	            return "buySuper.gif";
	        }elseif($nums > 2000)
	        {
	            return "buyMedal5.gif";
	        }elseif($nums > 1000)
	        {
	            return "buyMedal4.gif";
	        }elseif($nums > 500)
	        {
	            return "buyMedal3.gif";
	        }elseif($nums > 200)
	        {
	            return "buyMedal2.gif";
	        }else//if($nums >100)
	        {
	            return "buyMedal1.gif";
	        }
	    }
	}
}
//echo base64_encode('功能:取得相冊視頻的頻道分類');
?>
